/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月1日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.base.tools.ui.view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;

import org.apollo.base.tools.ui.action.BaseAction;
import org.apollo.base.tools.ui.constants.UIConstants;

/**
 * @ClassName: JlistPanel
 * @Description: 列表面板
 * @author wuzhenfang(wzfbj2008@163.com)
 * @date 2017年8月1日 下午5:43:22
 * @version V1.0
 */
public class JListLabelPanel extends JPanel {

	private static final long serialVersionUID = -9181344542027906788L;

	private static final int HORZ_PAD = 12;
	private static final int VERT_PAD = 6;

	public JListLabelPanel() {
		initComponents();
		Border b = BorderFactory.createEmptyBorder(VERT_PAD, HORZ_PAD, VERT_PAD, HORZ_PAD);
		setBorder(b);
	}

	private void initComponents() {
		FlowLayout layout = new FlowLayout(FlowLayout.LEADING, 15, 10);
		setLayout(layout);
	}

	public void addItem(String text, ImageIcon icon) {
		addItem(text, icon, null);
	}

	public void addItem(String text, Icon icon, final BaseAction action) {
		LinkLabel lblItem = new LinkLabel();
		lblItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				if (action != null) {
					action.actionPerformed(event);
				} else {
					System.out.println(((LinkLabel) event.getSource()).getText());
				}
			}
		});
		
		if (icon != null) {
			lblItem.setIcon(icon);
			lblItem.setForeground(Color.LIGHT_GRAY);
		} else {
			lblItem.setForeground(Color.LIGHT_GRAY);
		}
		lblItem.setText(text);
		add(lblItem);
	}

	public void addButtonItem(String text, ImageIcon icon) {
		JButton btnItem = new JButton();
		btnItem.setBorderPainted(true);
		btnItem.setBorder(BorderFactory.createCompoundBorder());
		btnItem.setBackground(Color.WHITE);
		if (icon != null) {
			btnItem.setIcon(icon);
		}
		btnItem.setForeground(Color.WHITE);
		btnItem.setText(text);
		add(btnItem);
	}

//	public void addListItem() {
//		String[] data = { "one", "two", "three", "four" };
//		JList lstItem = new JList(data);
//		lstItem.addMouseListener(new MouseAdapter() {
//			public void mouseEntered(MouseEvent e) {
//				lstItem.setCursor(new Cursor(Cursor.HAND_CURSOR));
//			}
//		    public void mouseExited(MouseEvent e) {
//		    	lstItem.setCursor( Cursor.getDefaultCursor());
//		    }
//		});
//		add(lstItem);
//	}

}
